<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
  Created by IntelliJ IDEA.
  User: 王有为
  Date: 2021/5/7
  Time: 13:03
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <meta charset="utf-8">
    <title>Layui</title>
    <%
        //获取项目的根路径
        String path = request.getContextPath();
        String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
    %>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">

    <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
    <%--    <link rel="stylesheet" type="text/css" href="http://localhost:8080/com_huazi_www_war_exploded/sweetalert.css">--%>
    <link rel="stylesheet" type="text/css" href="<%=basePath%>swee/sweetalert.css">
    <script type="text/javascript" src="<%=basePath%>swee/sweetalert-dev.js"></script>

</head>
<style>

    .tobu {
        text-align: center;
    }

    .fenye {
        text-align: center;
    }

    #close {
        width: 50px;
        height: 50px;
        position: absolute;
        padding-left: 550px;
        z-index: 999;
    }
</style>

<link rel="stylesheet" href="<%=basePath%>layui-v2.6.5/layui/css/layui.css" media="all">
<body>

<form action="<%=basePath%>DepartmentServlet?tp=select" method="post">
    <div class="tobu">
        <div class="layui-input-inline">
            <input type="text" name="userName" lay-verify="required" placeholder="请输入姓名" autocomplete="off"
                   class="layui-input" value="${userName}">
        </div>
        <button type="submit" class="layui-btn layui-btn-normal layui-btn-radius" style="background-color:#009f95">查询
        </button>
    </div>
    <%--拍照按钮--%>
    <button type="button" class="layui-btn layui-btn-normal" id="pictures" style="background-color:#009f95">待检查</button>
    <button type="button" class="layui-btn layui-btn-normal" id="pictureed" style="background-color:#009f95">已照片
    </button>
</form>
<div id="ct">
    <table class='layui-table' lay-even='' lay-skin='nob'>
        <colgroup>
            <col width='150'>
            <col width='150'>
            <col width='200'>
            <col>
        </colgroup>
        <thead>
        <tr>
            <th>编号</th>
            <th>姓名</th>
            <th>诊断时间</th>
            <th>诊断类型</th>
            <th>操作</th>
        </tr>
        </thead>
        <tbody>
        <c:forEach items="${requestScope.pageList.list}" var="list"> <%--forEach调用准备拍照的记录--%>
        <tr>
            <td>${list.id}</td>
            <td>${list.userName}</td>
            <td>${list.userTime}</td>
            <td>${list.userType}</td>
            <td><a href="javaScript:void (0)" onclick="selectid(${list.id},2)">
                <button type="submit" class="layui-btn layui-btn-normal layui-btn-radius"
                        style="background-color:#009f95">确定照片
                </button>
            </a></td>
        </tr>
        </c:forEach>
    </table>
    <%--分页--%>
    <div class="fenye">
        <c:if test="${requestScope.pageList.currentPage>1}">    <%--判断显示的当前页码是否大于1--%>
            <a href="<%=basePath%>DepartmentServlet?currentPage=${requestScope.pageList.currentPage-1}&tp=select&userName=${userName}">上一页</a>
        </c:if>
        ${requestScope.pageList.currentPage}/${requestScope.pageList.totalPage} <%--页码--%>
        <c:if test="${requestScope.pageList.currentPage<requestScope.pageList.totalPage}">  <%--判断当前页码是否小于总页数--%>
            <a href="<%=basePath%>DepartmentServlet?currentPage=${requestScope.pageList.currentPage+1}&tp=select&userName=${userName}">下一页</a>
        </c:if>
    </div>
</div>

<%--准备诊断--%>
<div id="diagnosis" style="display: none">
    <table class='layui-table' lay-even='' lay-skin='nob'>
        <colgroup>
            <col width='150'>
            <col width='150'>
            <col width='200'>
            <col>
        </colgroup>
        <thead>
        <tr>
            <th>编号</th>
            <th>姓名</th>
            <th>诊断时间</th>
            <th>操作</th>
        </tr>
        </thead>
        <tbody>
        <c:forEach items="${requestScope.pagesList.list}" var="lists"> <%--forEach调用已经拍照的记录--%>
        <tr>
            <td>${lists.id}</td>
            <td>${lists.userName}</td>
            <td>${lists.userTime}</td>
            <td><a href="javaScript:void (0)">
                <button type="submit" class="layui-btn layui-btn-normal layui-btn-radius photos"
                        style="background-color:#009f95">查看照片
                </button>
            </a></td>
        </tr>
        </c:forEach>
    </table>

    <%--新增CT记录--%>
    <div style="display: none;width: 600px;height: 700px;position: absolute;top: 100px;left: 30%;background-color: whitesmoke"
         class="definite">
        <div class="login">
            <img src="<%=basePath%>depa/img/huaziloge.png" width="100px" height="100px" style="position: absolute">
            <%--关闭--%>
            <div id="close">
                <img src="<%=basePath%>depa/img/close.png" width="50px" height="50px" id="guan">
            </div>
            <h2 style="position: relative;left: 200px;padding-top: 20px">湖南省长沙市华子医院</h2>
            <h2 style="position: relative;left: 183px;padding-top: 10px">HuNanShengHuaZiYiYuan</h2>
            <p style="padding-left: 400px">检查日期:${time}</p>
            <hr>
            <p id="ctId" style="display: none">患者编号:<span></span></p>
            <p id="ctName">姓名:<span></span></p>
            <p id="ctTime" style="display: none">时间:<span></span></p>
            <hr>
            <img src="<%=basePath%>depa/img/ct.jpg" width="300px" height="400px" style="padding-left: 150px">
            <p style="padding-left: 270px; padding-top: 30px">
                <button type="submit" class="layui-btn layui-btn-normal layui-btn-radius" id="zd"
                        style="background-color:#009f95">诊断
                </button>
            </p>

        </div>
    </div>
    <%--分页--%>

    <div class="fenye">
        <c:if test="${requestScope.pagesList.currentPage>1}">    <%--判断显示的当前页码是否大于1--%>
            <a href="<%=basePath%>DepartmentServlet?currentPage=${requestScope.pagesList.currentPage-1}&tp=select&userName=${userName}">上一页</a>
        </c:if>
        ${requestScope.pagesList.currentPage}/${requestScope.pagesList.totalPage} <%--页码--%>
        <c:if test="${requestScope.pagesList.currentPage<requestScope.pagesList.totalPage}">  <%--判断当前页码是否小于总页数--%>
            <a href="<%=basePath%>DepartmentServlet?currentPage=${requestScope.pagesList.currentPage+1}&tp=select&userName=${userName}">下一页</a>
        </c:if>
    </div>
</div>

<script type="text/javascript" src="<%=basePath%>jquery/jquery-1.12.4.js"></script>
<script type="text/javascript">

    //默认显示拍照
    $(function () {
        $("#guan").click(function () {  //点击关闭图片
            $(".definite").hide();  //隐藏新增CT记录
        })
        $("#pictureed").click(function () {  //点击已照片
            $("#ct").css("display", "none"); //隐藏拍照
            $("#diagnosis").css("display", "block"); //显示准备诊断
        })
        $("#pictures").click(function () {  //点击待检查
            $("#ct").css("display", "block");    //显示拍照
            $("#diagnosis").css("display", "none");  //隐藏诊断
        })
        $(".photos").click(function () {    //点击查看照片
            $(".definite").css("display", "block");  //显示新增Ct记录
            $("#ctId span").text($(this).parent().parent().parent().find("td:eq(0)").text());   //获取诊断号
            $("#ctName span").text($(this).parent().parent().parent().find("td:eq(1)").text()); //获取用户名
            $("#ctTime span").text($(this).parent().parent().parent().find("td:eq(2)").text()); //获取当前时间
        })
        $("#zd").click(function () {

            swal({
                title: "<small>请输入诊断信息</small>!",
                text: "请输入检查部位 <input type='text' name='myinput' id='part'>"
                    + "请输入检查结果 <input type='text' name='myinput' id='situation'>",
                html: true,
                type: "input",
            }, function () {

                zds();

            })

        })
    })

    /**
     * 修改
     * @param id    编号
     * @param state
     */
    function zds() {
        var parts = document.getElementById('part').value; //弹出框
        // if (parts==null||parts==""){  //判断part是否为空
        //     return false;   //为空结束
        // }
        var situations = document.getElementById('situation').value;     //弹出框
        // if (situations==null||situations==""){     //判断situation是否为空
        //     return false;   //为空结束
        // }
        var ctNum = $("#ctId span").text();
        var ctName = $("#ctName span").text();
        var ctTime = $("#ctTime span").text();
        var docId = "123456";
        $.ajax({
            url: "http://localhost:8080/com/DepartmentServlet",
            data: {
                ctNum: ctNum,
                ctName: ctName,
                ctTime: ctTime,
                part: parts,
                situation: situations,
                docId: docId,
                tp: "ins"   //插入
            },
            dataType: "json",
            type: "POST",
            success: function (data) {
                swal("确定！", "", "success");
                //局部刷新
                setInterval(function () {
                    location.reload()
                }, 1000);


            }
        })
    }

    function selectid(id, state) {

        swal({
                title: "是否拍照",
                type: "warning",
                showCancelButton: true,
                confirmButtonColor: "#DD6B55",
                confirmButtonText: "确定！",
                cancelButtonText: "取消！",
                closeOnConfirm: false,
                closeOnCancel: false
            },
            function (isConfirm) {
                if (isConfirm) {
                    $.ajax({
                        url: "http://localhost:8080/com/DepartmentServlet",
                        data: {
                            id: id,
                            state: state,
                            tp: "updateid"   //修改
                        },
                        dataType: "json",
                        type: "POST",
                        success: function (data) {

                            swal("确定！", "", "success");
                            setInterval(function () {
                                location.reload()
                            }, 1000);

                        }
                    })
                } else {
                    swal("取消！", "取消成功:)",
                        "error");
                }
            });
    }

</script>
</body>
</html>
